<!DOCTYPE html>
<html>
  
  <head>
    {include file="common/meta" /}
  </head>
  
  <body class="layui-anim layui-anim-up">
    <div class="x-body">
        <!-- 搜索 -->
      <div class="layui-row">
        <form method="get" class="layui-form layui-col-md12 x-so">
          <input class="layui-input" placeholder="开始日" name="start" id="start" value="" />

          <input class="layui-input" placeholder="截止日" name="end" id="end" value="" />

          <input type="text" name="keywords"  placeholder="请输入昵称或邮箱" autocomplete="off" value="" class="layui-input">
          
          <button class="layui-btn">
              <i class="layui-icon">&#xe615;</i>
          </button>
        </form>
      </div>

      <!-- 删除 -->
      <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <a href="{:url('admin/product/add')}" class="layui-btn"><i class="layui-icon"></i>添加</a>
        <span class="x-right" style="line-height:40px">共有数据：{$count} 条</span>
      </xblock>

      <!-- 分页列表 -->
      <table class="layui-table">
        <thead>
          <tr>
            <th>
              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>商品名称</th>
            <th>商品所属分类</th>
            <th>商品价格</th>
            <th>商品类型</th>
            <th>商品库存</th>
            <th>操作</th></tr>
        </thead>
        <tbody>
            {foreach $productlist as $item}
            <tr>
                <td>
                  <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$item.id}'><i class="layui-icon">&#xe605;</i></div>
                </td>
                <td>{$item.name}</td>
                <td>{$item.type.name}</td>
                <td>{$item.price}</td>
                <td>{$item.flag_text}</td>
                <td>{$item.stock}</td>
                <td class="td-manage">
                  <a title="修改用户信息" class="layui-btn layui-btn-sm layui-btn-normal" href="{:url('admin/product/edit',['proid'=>$item.id])}">
                    编辑
                  </a>
                  <a  class="layui-btn layui-btn-sm layui-btn-warm" title="消费记录" href="javascript:;" onClick="x_admin_show('消费记录',`{:url('admin/user.user/record',['userid'=>$item.id])}`)">
                    查看详情
                  </a>
                  <a title="删除" class="layui-btn layui-btn-sm layui-btn-danger" onclick="member_del(this,'{$item.id}')" href="javascript:;">
                    删除
                  </a>
                </td>
            </tr>
            {/foreach}
        </tbody>
      </table>

      <!-- 分页 -->
      <div class="page">
        {$pagestr}
      </div>
    </div>
  </body>
</html>
<script>
  // 单个删除
  function member_del(obj,id){
    layer.confirm('确认要删除吗？',function(index){
      del(id)
    });
  }

  // 批量删除
  function delAll(argument)
  {
    var data = tableCheck.getData();
    layer.confirm('确认要删除吗？',function(index){
      // 讲数组转换为字符串
      var ids = data.join(',')
      del(ids)
    });
  }

  // 删除的异步请求
  function del(data)
  {
    // 序列化 将对象转换为参数形式
    var params = {
      ids:data
    }

    params = $.param(params)

    $.ajax({
      url:`{:url('admin/user.User/del')}`,
      type:'post',
      data:params,
      dataType:'json',
      success:function(success)
      {
        layer.msg(success.msg,{icon:5,time:1000},function(){
          location.reload()
        })
      }
    })
  }
</script>